﻿using System;
using System.Drawing;
using System.Collections.Generic;
using DC2010.Objects.Data;
using DC2012.Render;
using DC2010;
using DC2010.Objects;

namespace DC2012
{
    public partial class Core
    {
        private Point origin = new Point();
        private WallPoints wpts = new WallPoints();

        public void ChangeVisibility()
        {
            //DetermineVisibility(-2, -2);
            //DetermineVisibility(-2, -3);
            //DetermineVisibility(2, -2);
            //DetermineVisibility(2, -3);

            DetermineVisibility(-1, 0);
            DetermineVisibility(-1, -1);
            DetermineVisibility(-1, -2);
            DetermineVisibility(-1, -3);

            DetermineVisibility(1, 0);
            DetermineVisibility(1, -1);
            DetermineVisibility(1, -2);
            DetermineVisibility(1, -3);

            DetermineVisibility(0, -4);
            DetermineVisibility(0, -3);
            DetermineVisibility(0, -2);
            DetermineVisibility(0, -1);
        }

        public void DetermineVisibility(int side, int depth)
        {
            //DCAnimatedSprite normal = Neocortex.I.GetAnimatedSprite_Simply("WALLSET_DEFAULT_" + NumberToString(side) + "_" + NumberToString(depth));
            //DCAnimatedSprite alt = Neocortex.I.GetAnimatedSprite_Simply("WALLSET_DEFAULT_ALT_" + NumberToString(side) + "_" + NumberToString(depth));

            Layer l = Root.I.GameSystem.CurrentLayer;
            PartyData pd = Root.I.GameSystem.Party;

            TileData td =
                (TileData)
                Root.I.MovementSystem.GetTile(pd.Location.X, pd.Location.Y, side, depth, pd.Location.Facing, l);

            //if ((normal!=null)&&(alt!=null))
            //{
            //    if (td != null)
            //    {
            //        normal.Visible = td.TypeTile == TileType.Wall;
            //        alt.Visible = td.TypeTile == TileType.Wall;
            //    }
            //    else
            //    {
            //        normal.Visible = true;
            //        alt.Visible = true;
            //    }
            //}
        }

        public void PrepareDungeonGfx()
        {
            //new
//            SetCoordinates("WALLSET_DEFAULT_M2_M2", -2, -2);
  //          SetCoordinates("WALLSET_DEFAULT_2_2", 2, -2);
    //        SetCoordinates("WALLSET_DEFAULT_M2_3", -2, -3);
      //      SetCoordinates("WALLSET_DEFAULT_2_3", 2, -3); 
            
            SetCoordinates("WALLSET_DEFAULT_1_0", 1, 0);
            SetCoordinates("WALLSET_DEFAULT_1_M1", 1, -1);
            SetCoordinates("WALLSET_DEFAULT_1_M2", 1, -2);
            SetCoordinates("WALLSET_DEFAULT_1_M3", 1, -3);

            SetCoordinates("WALLSET_DEFAULT_M1_0", -1, 0);
            SetCoordinates("WALLSET_DEFAULT_M1_M1", -1, -1);
            SetCoordinates("WALLSET_DEFAULT_M1_M2", -1, -2);
            SetCoordinates("WALLSET_DEFAULT_M1_M3", -1, -3);



            SetCoordinates("WALLSET_DEFAULT_0_M4", 0, -4);
            SetCoordinates("WALLSET_DEFAULT_0_M3", 0, -3);
            SetCoordinates("WALLSET_DEFAULT_0_M2", 0, -2);
            SetCoordinates("WALLSET_DEFAULT_0_M1", 0, -1);
        }

        private void SetCoordinates(string code, int X, int Y)
        {
          //  DCAnimatedSprite normal = Neocortex.I.GetAnimatedSprite(code);
          //  DCAnimatedSprite alt = Neocortex.I.GetAnimatedSprite(code.Replace("DEFAULT", "DEFAULT_ALT"));

            WallPoint wp = wpts[X, Y];

            //if ((wp!=null)&&(normal!=null)&&(alt!=null))
            //{
            //    normal.X = wp.Wall.X;
            //    normal.Y = wp.Wall.Y;

            //    alt.X = wp.Wall.X;
            //    alt.Y = wp.Wall.Y;

            //    if (X==0)
            //    {
            //        AddSprite(normal, corridorcenter);
            //        AddSprite(alt, corridorcenter);  
            //    }
            //    else
            //    {
            //        AddSprite(normal, corridor[Math.Abs(Y)]);
            //        AddSprite(alt, corridor[Math.Abs(Y)]);                    
            //    }



            //}
        }

        private string NumberToString(int i)
        {
            if (i < 0) return "M" + Math.Abs(i);
            return i.ToString();
        }
    }
}
